from pyecharts.options import InitOpts
from pyecharts import options as opt
from pyecharts.charts import *
from getRoute import Route
import pandas as pd


baidu_ak = ''
with open('config/key.txt', 'r') as p:
    baidu_ak = p.readlines()[1]


def makeGeo(data, TofileName):
    ID = data['VehicleID'].values.tolist()
    Start_Lon = data['SLon']
    Start_Lat = data['SLat']
    rownum = data['rownum']
    End_Lon = data['ELon']
    End_Lat = data['ELat']
    opts = InitOpts()
    geo = BMap()
    geo.add_schema(
        baidu_ak,
        center=(104.07, 30.67),
        zoom=12,
    )
    # 显示路线条数
    for item in range(10):
        route = Route.getRoute([Start_Lon[item], Start_Lat[item]],
                               [End_Lon[item], End_Lat[item]])
        start_item = 'start'+str(item)
        end_item = 'end'+str(item)
        geo.add_coordinate(
            start_item,
            Start_Lon[item],
            Start_Lat[item]
        )
        geo.add_coordinate(
            end_item,
            End_Lon[item],
            End_Lat[item]
        )
        geo.add(
            color='#00ff00',
            series_name='开始点',
            data_pair=[(start_item, 0)],
        ).add(
            color='#ff0000',
            series_name='结束点',
            data_pair=[(end_item, 1)]
        ).add(
            '路程线',
            [route],
            type_='lines',
            is_polyline=True,
            is_large=True,
            linestyle_opts=opt.LineStyleOpts(
                color="#000000",  width=1),
        )
    geo.render(f"view/{TofileName}.html")


if __name__ == '__main__':
    datas = pd.read_excel('data/data.xlsx')
    makeGeo(datas, 'map')
